﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Bouyei.Geo.GeoParsers.Parser
{
    using Geometries;
    using Wkt;

    public class WktParser:IDisposable
    {
        public GeoType GeometryType { get; private set; }
        GeometryWriter writer = null;
        GeometryReader reader = null;

        public WktParser()
        {
            writer = new GeometryWriter();
        }

        public List<List<Coordinate[]>> FromReader(string wkt)
        {
            using (reader = new GeometryReader(wkt))
            {
                GeometryType=reader.GeometryType;
                return reader.ReaderCoodinates();
            }
        }

        public Geometry Reader(string wkt)
        {
            using (reader = new GeometryReader(wkt))
            {
                GeometryType = reader.GeometryType;
                return reader.Reader();
            }
        }

        public string ToWriter(Geometry geometry)
        {
            return writer.Writer(geometry);
        }
        public string ToWriter(List<List<Coordinate[]>> coordinates,
        GeoType geoType = GeoType.POLYGON)
        {
            return writer.Writer(coordinates, geoType);
        }


        public void Dispose()
        {
            if (reader != null)
            {
                reader.Dispose();
                reader = null;
            }
            writer = null;
        }
    }
}
